<?php

require_once './include/common.inc.php';

$page_title = 'jans2en furniture - Login - Request an Authorized Dealer Account';

$webmaster_name = 'test';
$webmaster_email = 'allen@imaker.com.cn';

getMyParam('act');
$register_is_ok = false;

if ($act == "register") {
    getMyParam('dealerinquirycompany');
    getMyParam('dealerinquiryfirstname');
    getMyParam('dealerinquirylastname');
    getMyParam('dealerinquirybusinesstype');
    getMyParam('dealerinquiryyearsinbusiness');
    getMyParam('dealerinquiryaddress');
    getMyParam('dealerinquiryaddress2');
    getMyParam('dealerinquirycity');
    getMyParam('stateid');
    getMyParam('countryid');
    getMyParam('dealerinquirypostal');
    getMyParam('dealerinquiryphone');
    getMyParam('dealerinquiryfax');
    getMyParam('dealerinquiryemail');
    getMyParam('dealerinquiryregistrationnumber');
    getMyParam('dealerinquiryurl');
    getMyParam('find_us_content');
    getMyParam('comments');
    getMyParam('company_content');


    $sql = "SELECT `id`, `username`, `email` FROM `user` WHERE `email` = '$dealerinquiryemail' AND `status` <>3";
    $rs = $db->get_one($sql);
    if (!empty($rs)) {
        echo "<script>alert('Email exist.');history.back(1);</script>";
        exit;
    }

    if (trim($dealerinquirycompany) == "" || trim($dealerinquiryphone) == "" || trim($dealerinquiryemail) == "" || $countryid == 0  || trim($dealerinquirycity) == "" || trim($dealerinquiryaddress) == "" || trim($dealerinquirylastname) == "") {
        echo "<script>alert('Please enter content.');history.back(1);</script>";
        exit;
    } else {
        $sql = "INSERT INTO `user` (`firstname` , `lastname` , `company` , `business_type` , `business_year` , `address` , `address2` , `city` , `stateid` , `countryid` , `zip` , `phone` , `fax` , `email` , `company_number` , `url` , `find_us_content` , `comments` , `company_content`  )
                VALUES (
                '$dealerinquiryfirstname', '$dealerinquirylastname', '$dealerinquirycompany', '$dealerinquirybusinesstype', '$dealerinquiryyearsinbusiness', '$dealerinquiryaddress', '$dealerinquiryaddress2', '$dealerinquirycity', '$stateid', '$countryid', '$dealerinquirypostal', '$dealerinquiryphone', '$dealerinquiryfax', '$dealerinquiryemail', '$dealerinquiryregistrationnumber', '$dealerinquiryurl', '$find_us_content', '$comments', '$company_content'
                )";
        $db->query($sql);

        require_once './mail/register_to_dealer2.php';
        sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
		
        $system_ary = getSystemValue("");
		$webmaster_name = $system_ary['webmaster_name'];
		$webmaster_email = $system_ary['webmaster_email'];
        require_once './mail/register_to_webmaster2.php';
        sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);

        header("location:register.php?act=succeed");
        exit;
    }
}

if ($act == "succeed") {
    $register_is_ok = true;
}

foreach ($STATE_ARY as $k=>$v) {
    $state_select .= '<option value="' . $k . '" >' . $v . '</option>';
    if ($k==51) {
        $state_select .= '<option value="">--------------------------</option><option value="">CANADIAN PROVINCES</option><option value="">--------------------------</option>';
    }
}
foreach ($COUNTRY_ARY as $k=>$v) {
    $country_select .= '<option value="' . $k . '" >' . $v . '</option>';
}

require_once PrintEot('header');
require_once PrintEot('register');
require_once PrintEot('footer');

?>
